import axios from 'axios'

const request = {}

// '/api'字段已在vue.config.js配置
request.globalRequest = (url, method, data, headers, type) => {
	let apiUrl = ''
	if(process.env.NODE_ENV == 'development'){
		apiUrl = '/api'
	}else if(process.env.NODE_ENV == 'production'){
		apiUrl = process.env.VUE_APP_BASE_URL
	}
	return new Promise((resolve, reject) => {
		axios({
		method,
		url: apiUrl + url,
		data,
		headers:{
			'Content-Type': 'text/plain;'
		}
		}).then(function (res) {
			resolve(res.data)
		}).catch(function (res) {
			resolve(res.data)
		})
	});
}


export default request
